<template>
	<view class="home">
		<view class="search">
			<my-search @click='toSearch' :radius="35"></my-search>
		</view>
		<!-- 轮播图 -->
		<swiper class="swiper" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
			<swiper-item v-for="(item,index) in swiperList" :key="index">
				<navigator :url="item.navigator_url">
					<image class="image" :src="item.image_src"></image>
				</navigator>
			</swiper-item>
		</swiper>

		<!-- 中间导航栏 -->
		<view class="cate">
			<view class="item" @click="toCate(index)" v-for="(item,index) in cateList" :key="index">
				<image class="image" :src="item.image_src" mode=""></image>

			</view>
		</view>
		<!-- floor列表栏 -->
		<view class="floor">
			<view class="item" v-for="(item,index) in floorList" :key="index">
				<view class="title">
					<image class="image" :src="item.floor_title.image_src" mode=""></image>
				</view>
				<view class="imageList">
					<view class="left">
						<image class="image" @click="toList(item.product_list[0].name)"
							:src="item.product_list[0].image_src"
							:style="{width:`${item.product_list[0].image_width}rpx`}" mode=""></image>
					</view>
					<view class="right">
						<block v-for="(v,i) in item.product_list" :key="i">
							<image class="image" @click="toList(v.name)" :src="v.image_src"
								:style="{width:`${v.image_width}rpx`}" v-if="i!==0" mode="">
							</image>
						</block>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import mymixins from '../../mixins/index.js'
	export default {
		mixins: [mymixins],
		data() {
			return {
				swiperList: [],
				cateList: [],
				floorList: [],

			};
		},

		onLoad() {
			this.getSwiperList()
			this.getcateList()
			this.getfloorList()
		},
		methods: {

			// 获取轮播图列表
			async getSwiperList() {

				const res = await uni.$http.get('/api/public/v1/home/swiperdata')
				if (res.data.meta.status !== 200) {
					/* return uni.showToast({
						title: '出错啦...',
						icon: 'error'
					}) */
					return uni.$showMsg()
				}
				this.swiperList = res.data.message
			},
			// 获取中间导航栏列表
			async getcateList() {
				const res = await uni.$http.get('/api/public/v1/home/catitems')
				// if (res.data.meta.status !== 200) return uni.$showMsg()
				this.cateList = res.data.message
			},
			// 跳转到cate分类页面
			toCate(index) {
				if (index === 0) {
					uni.switchTab({
						url: '/pages/cate/cate'
					})
				}
			},
			// 获取floor图片列表
			async getfloorList() {
				const res = await uni.$http.get('/api/public/v1/home/floordata')
				// console.log(res);
				this.floorList = res.data.message
			},
			// 跳转至list详情页面
			toList(key) {
				uni.navigateTo({
					url: `/pages/list/list?key=${key}`
				})
				// console.log(key);
			},
			// 跳转至搜索页面
			toSearch() {
				uni.navigateTo({
					url: '/pages/search/search'
				})
			}
		}

	}
</script>

<style lang="scss">
	* {
		margin: 0;
		padding: 0;
		box-sizing: border-box;
	}

	.search {
		position: sticky;
		top: 0;
		left: 0;
		z-index: 99;
	}

	.swiper {
		height: 360rpx;

		.image {
			width: 100%;
			height: 360rpx;
		}
	}

	.cate {
		width: 100%;
		height: 100px;
		display: flex;
		justify-content: space-around;


		// background-color: red;
		.item {
			width: 25%;
			height: 100%;
			text-align: center;
			margin-top: 20px;

			.image {
				width: 60px;
				height: 60px;
			}
		}
	}

	.floor {
		width: 100%;
		height: 270px;

		.item {
			height: 240px;
			margin: 5px;

			.title {
				height: 28px;

				.image {
					height: 28px;
				}
			}

			.imageList {
				display: flex;

				.left {
					margin-right: 5px;

					.image {
						height: 200px;
					}
				}

				.right {
					display: flex;
					flex-wrap: wrap;

					.image {
						height: 95px;

						&:nth-child(1),
						&:nth-child(3) {
							margin-right: 10px;
						}
					}
				}
			}
		}
	}
</style>
